<?php
namespace app\index\model;

class Wx extends BaseModel
{
    public $configs = [];
    //初始化构造方法
    public function __construct()
    {
        $this->configs['APPID'] = 'wx717709d7d0187b75';
        $this->configs['MCHID'] = '1429707502';
        $this->configs['KEY'] = '0A00986B9BA7AF0981A6A705D0B429F1';
        $this->configs['APPSECRET'] = '2ffbf3595075f96efb9fa82475f0a219';
    }

    //进行授权
    public function openauths($redirect_uri)
    {
        $appid = $this->configs['APPID'];
        $state = '0';
        $data['url'] = 'http://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.urlencode($redirect_uri).'&response_type=code&scope=snsapi_base&state='.$state.'#wechat_redirect';
        return view('jump',$data);
    }

    //code换取token
    public function getToken($appid,$secret,$code)
    {
        return request_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.
            '&secret='.$secret.'&code='.$code.'&grant_type=authorization_code');
    }

    //获取用户信息
    public function getUserInfo($access_token,$openid)
    {
        return request_get('https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid.'&lang=zh_CN');
    }
}